package servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.simple.JSONArray;

import dao.MySql;

public class WaitingList extends HttpServlet implements Servlet {
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try{
			String func = request.getParameter("func");
			if(func==null||func.trim().length()==0)func = "xfunc";
    		PrintWriter pw = response.getWriter();
			List<String[]> list = new MySql().getWaitLists();
    		JSONArray ja = new JSONArray();
			for(int i=0;i<list.size();i++){
				String cols[] = list.get(i);
    	        ja.add(cols[0]+":"+cols[1]);
			}
			pw.println(func+" (\n"+ja+");\n");
		}catch(Exception e){
			e.printStackTrace();
		}
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request,response);
	}

}
